package main

import (
	"fmt"
	"sync"
	"time"
)

var wg sync.WaitGroup

func write(intChan chan int){
	defer wg.Done()
	for i :=1;i <= 10;i++{
		intChan <- i
		fmt.Println("写入的数据为：",i)
		// time.Sleep(time.Second)
	}
}

func read(intChan chan int){
	defer wg.Done()
	for i := range intChan{
		fmt.Println("输出的数据为：",i)
		time.Sleep(time.Second)
	}
}

func main(){
	intChan := make(chan int,10)

	wg.Add(2)

	go write(intChan)
	go read(intChan)	//如果一直写入，但是没有读取，则会出现死锁

	wg.Wait()
}